package com.bw.heishou.mvp.model;

import com.bw.heishou.Bean.UserBean;
import com.bw.heishou.HeiApi;
import com.bw.heishou.mvp.contract.UserContract;
import com.bw.lib_core.http.RetrofitManager;
import com.bw.lib_core.mvp.model.BaseModel;
import com.google.gson.JsonObject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class LogModel extends BaseModel implements UserContract.User_Model {
    @Override
    public void reg(String url,String user, String pass, Observer<UserBean> observer) {

        JsonObject jsonObject=new JsonObject();
        jsonObject.addProperty("phoneNum",""+user);
        jsonObject.addProperty("userPassWord",""+pass);
        RequestBody requestBody=RequestBody.create(MediaType.parse("application/json"),jsonObject.toString());
        RetrofitManager.getRetrofitManager()
                .create(url)
                .create(HeiApi.class)
                .reg(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void log(String url, String user, String pass, Observer<UserBean> observer) {
        JsonObject jsonObject=new JsonObject();
        jsonObject.addProperty("phoneNum",""+user);
        jsonObject.addProperty("userPassWord",""+pass);
        RequestBody requestBody=RequestBody.create(MediaType.parse("application/json"),jsonObject.toString());

        RetrofitManager.getRetrofitManager()
                .create(url)
                .create(HeiApi.class)
                .log(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
